{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>操作书籍</title>
    <link href="{% static 'plugins/bootstrap-3.3.7-dist/css/bootstrap.min.css' %}" rel="stylesheet">
    <script src="{% static 'js/jquery.js' %}"></script>
    <script src="{% static 'plugins/bootstrap-3.3.7-dist/js/bootstrap.min.js' %}"></script>
</head>
<body>
<div class="container">
    <h1>编辑书籍</h1>

    <div class="row">
        <div class="col-md-4 ">
            {% if old_book_obj %}
                <form action="{% url 'edit_book' old_book_obj.pk %}" method="post" class="form-horizontal">
            {% else %}
                <form action="{% url 'add_book'  %}" method="post" class="form-horizontal">
            {% endif %}

            <div class="form-group">
                <label for="title">书籍名称</label>
                <input type="text" class="form-control" id="title" placeholder="书籍名称" name="title"
                       value={{ old_book_obj.title }}>
            </div>
            <div class="form-group">
                <label for="price">书籍价格</label>
                <input type="text" class="form-control" id="price" placeholder="书籍价格" name="price"
                       value={{ old_book_obj.price }}>
            </div>
            <div class="form-group">
                <label for="pub_date">出版日期</label>
                <input type="date" class="form-control" id="pub_date" placeholder="出版日期" name="pub_date"
                       value={{ old_book_obj.pub_date|date:"Y-m-d" }}>
            </div>
            <div class="form-group">
                <label for="publish">出版社</label>
                <select name="pub_id" id="publish" class="form-control">
                    {% for publish in publish_list %}
                        {% if old_book_obj.pub == publish %}
                            <option value="{{ publish.id }}" selected>{{ publish.name }}</option>
                        {% else %}
                            <option value="{{ publish.id }}">{{ publish.name }}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            </div>
            <div class="form-group">
                <label for="authors">作者</label>
                <select multiple name="authors" id="authors" class="form-control">
                    {% for author in author_list %}
                        {% if author in old_book_obj.authors.all %}
                            <option value="{{ author.id }}" selected>{{ author.name }}</option>
                        {% else %}
                            <option value="{{ author.id }}">{{ author.name }}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            </div>
            <button class="btn btn-success pull-right">提交</button>
            </form>
        </div>
    </div>

</div>
</body>
</html>